#ifndef SCENE_H
#define SCENE_H

#include <QList>
#include <QGraphicsScene>
#include "algorithm.h"

class QPainter;
class QPainter;
class QRectF;
class QGraphicsSceneMouseEvent;
class Cell;
class QColor;
class QPoint;

class Scene : public QGraphicsScene
{
    Q_OBJECT
public:
    explicit Scene(QObject *parent = 0);
    
    void drawLines();
    void setSceneRect(const QRectF &rect);
    void setAlg(Algorithm* alg);
    inline bool isInDebug() {return isDebug;}

protected:
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);

signals:
    void drawed();

public slots:
    void update(const QRectF &rect);
    void clear();
    void drawNext();
    void toDebug();

private:
    void drawPoints(PointsIter* points);
    void drawPointsAll(PointsIter* points);
    void drawPointsDebug(PointsIter* points);
    void clearTemp();
    Cell* drawPoint(QPoint point, bool isSpecial);
    int convert(int i);

    int mPixelSize;
    bool isDebug;
    QPixmap* mBackgroundPixmap;
    QPixmap* mUnderMousePixmap;
    QPixmap* mPointPixmap;
    Cell* mUnderMouseItem;
    QColor mUnderMouseItemColor;
    Algorithm* mAlg;
    QList<Cell*>* mTempPoints;
    PointsIter* mPointsIter;
};

#endif // SCENE_H
